home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr54 / bos2ol.zip / BOSS2OL.C next >
C/C++ Source or Header  |  1993-06-01  |  9KB  |  344 lines

  1. #include <alltcc.h>
  2.  
  3.  
  4. /****************************************************************************/
  5. void ConvertTime(char *t);
  6. void ConvertSchedule(char *inputLine, FILE *outfile);
  7. void ConvertPhone(char *inputLine, FILE *outfile);
  8. void ConvertBusiCard(char *inputLine, FILE *outfile);
  9. void ConvertNovellBusiCard(char *inputLine, FILE *outfile);
  10.  
  11.  
  12. /****************************************************************************/
  13. void main(int argc, char *argv[])
  14. {
  15.     FILE    *infile,
  16.             *outfile;
  17.     static char
  18.             inputLine[512];
  19.     int        i;
  20.     void    (*Convert)(char *inputLine, FILE *outfile);
  21.  
  22.     if (argc != 4)
  23.         exit(fprintf(stderr,
  24.                 "Usage: B2S type infile outfile\n"
  25.                 "       'type' can be one of the following\n"
  26.                 "            P = telePhone\n"
  27.                 "            B = Business card\n"
  28.                 "            N = Novell business card\n"
  29.                 "            S = Schedule\n"));
  30.  
  31.     switch (toupper(argv[1][0]))
  32.     {
  33.     case 'P':
  34.         /* phone */
  35.         Convert = ConvertPhone;
  36.         break;
  37.  
  38.     case 'B':
  39.         /* business card */
  40.         Convert = ConvertBusiCard;
  41.         break;
  42.  
  43.     case 'N':
  44.         /* business card */
  45.         Convert = ConvertNovellBusiCard;
  46.         break;
  47.  
  48.     case 'S':
  49.         /* schedule */
  50.         Convert = ConvertSchedule;
  51.         break;
  52.  
  53.     default:
  54.         printf("That type is unknown!\n");
  55.         break;
  56.     }
  57.  
  58.     infile = fopen(argv[2], "rt");
  59.     if (infile == NULL)
  60.         exit(fprintf(stderr, "Unable to open %s file\n", argv[2]));
  61.  
  62.     outfile = fopen(argv[3], "wt");
  63.     if (outfile == NULL)
  64.         exit(fprintf(stderr, "Unable to open %s file\n", argv[3]));
  65.  
  66.     while (fgets(inputLine, 512, infile) != NULL)
  67.     {
  68.         /* strip off the ending return / linefeed or space */
  69.         i = strlen(inputLine) - 1;
  70.         while (i >= 0 && inputLine[i] <= ' ')
  71.             inputLine[i--] = '\0';
  72.  
  73.         printf("%s\n", inputLine);
  74.  
  75.         Convert(inputLine, outfile);
  76.     }
  77.  
  78.     fclose(infile);
  79.     fclose(outfile);
  80. }
  81.  
  82.  
  83. /****************************************************************************/
  84. void ConvertSchedule(char *inputLine, FILE *outfile)
  85. {
  86.     static char
  87.             description[512],
  88.             startTime[7],
  89.             endTime[7],
  90.             alarmTime[7];
  91.     int        year,
  92.             month,
  93.             day;
  94.     /*
  95.         The format of the Casio (input) line is:
  96.         "1990-09-19","16:00","18:00","16:00","Webs"
  97.         "YYYY-MM-DD","START","END"  ,"ALARM","DESCRIPTION"
  98.  
  99.         The format of the Sharp (output) line is:
  100.         "03/25/1991","06:00p","09:00p","06:00p","FHE"
  101.         "MM/DD/YYYY","START" ,"END"   ,"ALARM" ,"DESCRIPTION"
  102.  
  103.         Operations to perform:
  104.             The date must be reformated
  105.             The times must be converted to 12 hour format
  106.     */
  107.  
  108.     sscanf(inputLine, "\"%d-%d-%d\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"\n",
  109.             &year, &month, &day,
  110.             startTime,
  111.             endTime,
  112.             alarmTime,
  113.             description);
  114.  
  115.     ConvertTime(startTime);
  116.     ConvertTime(endTime);
  117.     ConvertTime(alarmTime);
  118.  
  119.     fprintf(outfile, "\"%02d/%02d/%04d\",\"%s\",\"%s\",\"%s\",\"%s\"\n",
  120.             month, day, year,
  121.             startTime,
  122.             endTime,
  123.             alarmTime,
  124.             description);
  125. }
  126.  
  127.  
  128. /****************************************************************************/
  129. void ConvertTime(char *t)
  130. {
  131.     int        hours,
  132.             minutes;
  133.     char    ampm = 'a';
  134.  
  135.     if (sscanf(t, "%d:%d", &hours, &minutes) != 2)
  136.         t[0] = '\0';
  137.     else
  138.     {
  139.         if (hours >= 12)
  140.             ampm = 'p';
  141.  
  142.         if (hours > 12)
  143.             hours -= 12;
  144.  
  145.         if (hours == 0)
  146.             hours = 12;
  147.  
  148.         sprintf(t, "%02d:%02d%c", hours, minutes, ampm);
  149.     }
  150. }
  151.  
  152.  
  153. /****************************************************************************/
  154. void ConvertPhone(char *inputLine, FILE *outfile)
  155. {
  156.     static char
  157.             name[384],
  158.             phone[384],
  159.             address[384],
  160.             spouse[384],
  161.             otherInfo[5][384];
  162.     int        i;
  163.  
  164.     /*
  165.         The format of the Casio (input) line is:
  166.         "Aaron Rhoades","226-0784","210 W 2000 S","JoAnna","","","","",""
  167.  
  168.         The format of the Sharp (output) line is:
  169.         "AARON RHOADES","226-0784","210 W 2000 S"
  170.  
  171.         Operations to perform:
  172.             convert to upper case
  173.             append spouse to end of name field
  174.             append 5 "other info's" to address
  175.     */
  176.  
  177.     strupr(inputLine);
  178.  
  179.     sscanf(inputLine, "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"\n",
  180.             name, phone, address, spouse,
  181.             otherInfo[0], otherInfo[1], otherInfo[2], otherInfo[3], otherInfo[4]);
  182.  
  183.     fprintf(outfile, "\"%s", name);
  184.     if (spouse[0])
  185.         fprintf(outfile, "\t%s", spouse);
  186.  
  187.     fprintf(outfile, "\",\"%s\",\"%s", phone, address);
  188.     for (i = 0; i < 5; i++)
  189.         if (otherInfo[i][0])
  190.             fprintf(outfile, "\t%s", otherInfo[i]);
  191.  
  192.     fprintf(outfile, "\"\n");
  193. }
  194.  
  195.  
  196. /****************************************************************************/
  197. void ConvertBusiCard(char *inputLine, FILE *outfile)
  198. {
  199.     static char
  200.             employeer[384],
  201.             name[384],
  202.             phone[384],
  203.             position[384],
  204.             department[384],
  205.             pobox[384],
  206.             address[384],
  207.             telex[384],
  208.             fax[384],
  209.             homeAddress[384],
  210.             homePhone[384],
  211.             otherInfo[4][384];
  212.     int        i;
  213.  
  214.     /*
  215.         The format of the Casio (input) line is:
  216.         "employer","name","phone","position","department","p.o. box",
  217.                 "address","telex","fax","home address","home phone",
  218.                 "free3",...
  219.  
  220.         The format of the Sharp (output) line is:
  221.         "name","phone","address"
  222.  
  223.         Operations to perform:
  224.             convert to upper case
  225.             append employeer, position, department to name
  226.             append telex, fax and home phone to phone
  227.             append p.o. box, home address and 4 frees to address
  228.     */
  229.  
  230.     strupr(inputLine);
  231.  
  232.     sscanf(inputLine, "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\","
  233.             "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\","
  234.             "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"\n",
  235.             employeer, name, phone, position, department, pobox, address,
  236.             telex, fax, homeAddress, homePhone,
  237.             otherInfo[0], otherInfo[1], otherInfo[2], otherInfo[3]);
  238.  
  239.     fprintf(outfile, "\"%s", name);
  240.     if (employeer[0])
  241.         fprintf(outfile, "\t%s", employeer);
  242.     if (position[0])
  243.         fprintf(outfile, "\t%s", position);
  244.     if (department[0])
  245.         fprintf(outfile, "\t%s", department);
  246.  
  247.     fprintf(outfile, "\",\"%s", phone);
  248.     if (telex[0])
  249.         fprintf(outfile, "\t%s T", telex);
  250.     if (fax[0])
  251.         fprintf(outfile, "\t%s F", fax);
  252.     if (homePhone[0])
  253.         fprintf(outfile, "\t%s H", homePhone);
  254.  
  255.     fprintf(outfile, "\",\"%s", address);
  256.     if (pobox[0])
  257.         fprintf(outfile, "\t%s", pobox);
  258.     if (homeAddress[0])
  259.         fprintf(outfile, "\t%s H", homeAddress);
  260.  
  261.     for (i = 0; i < 4; i++)
  262.         if (otherInfo[i][0])
  263.             fprintf(outfile, "\t%s", otherInfo[i]);
  264.  
  265.     fprintf(outfile, "\"\n");
  266. }
  267.  
  268.  
  269. /****************************************************************************/
  270. void ConvertNovellBusiCard(char *inputLine, FILE *outfile)
  271. {
  272.     static char
  273.             employeer[384],
  274.             name[384],
  275.             phone[384],
  276.             position[384],
  277.             department[384],
  278.             pobox[384],
  279.             address[384],
  280.             telex[384],
  281.             fax[384],
  282.             homeAddress[384],
  283.             homePhone[384],
  284.             otherInfo[4][384];
  285.     int        i;
  286.  
  287.     /*
  288.         The format of the Casio (input) line is:
  289.         "employer","name","phone","position","department","p.o. box",
  290.                 "address","telex","fax","home address","home phone",
  291.                 "free3",...
  292.  
  293.         The format of the Sharp (output) line is:
  294.         "name","phone","address"
  295.  
  296.         Operations to perform:
  297.             convert to upper case
  298.             trash employeer (we know it is NOVELL)
  299.             append position, department to name
  300.             append telex, fax and home phone to phone
  301.             append p.o. box, home address and 4 frees to address
  302.     */
  303.  
  304.     strupr(inputLine);
  305.  
  306.     sscanf(inputLine, "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\","
  307.             "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\","
  308.             "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\"\n",
  309.             employeer, name, phone, position, department, pobox, address,
  310.             telex, fax, homeAddress, homePhone,
  311.             otherInfo[0], otherInfo[1], otherInfo[2], otherInfo[3]);
  312.  
  313.     fprintf(outfile, "\"%s", name);
  314.     if (position[0])
  315.         fprintf(outfile, "\t%s", position);
  316.     if (department[0])
  317.         fprintf(outfile, "\t%s", department);
  318.  
  319.     fprintf(outfile, "\",\"%s", phone);
  320.     if (telex[0])
  321.         fprintf(outfile, "\t%s T", telex);
  322.     if (fax[0])
  323.         fprintf(outfile, "\t%s F", fax);
  324.     if (homePhone[0])
  325.         fprintf(outfile, "\t%s H", homePhone);
  326.  
  327.     fprintf(outfile, "\",\"%s", address);
  328.     if (pobox[0])
  329.         fprintf(outfile, "\t%s", pobox);
  330.     if (homeAddress[0])
  331.         fprintf(outfile, "\t%s H", homeAddress);
  332.  
  333.     for (i = 0; i < 4; i++)
  334.         if (otherInfo[i][0])
  335.             fprintf(outfile, "\t%s", otherInfo[i]);
  336.  
  337.     fprintf(outfile, "\"\n");
  338. }
  339.  
  340.  
  341. /****************************************************************************/
  342. /****************************************************************************/
  343.  
  344.